home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #2
/
Amiga Plus CD - 2004 - No. 02.iso
/
AmiSoft
/
Gfx
/
conv
/
GIFsplit.lha
/
source
/
GifSplit.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1998-02-17
|
6KB
|
250 lines
/*
** GifSplit.rexx
** $ver: 0.99, 16 Feb 1998
*/
parse arg filename debug .
if debug~="" then debug=1
else debug=0
if ~open('in',filename,'r') then
do
say "GifSplit.rexx"
Say " Usage: Rx GifSplit <filename>"
say
Say " This script will take an animated gif file"
Say "and split it into the individual gifs."
exit 10
end
/* read identifier
** 6 bytes
*/
line = readch('in',6)
if line ~="GIF89a" & line ~="GIF87a" then
do
say filename "is not an gif."
exit 10
end
header=line
/*
** LSD - Logical Screen Descriptor (no, not a drug)
** reads the logical screen descriptor, 7 bytes
*/
LSD=readch('in',7)
width = c2d(reverse(substr(lsd,1,2)))
height = c2d(reverse(substr(lsd,3,2)))
stuff = c2b(substr(lsd,5,1))
GlobalColor = c2d(b2c(substr(stuff,1,1)))
colorRes = c2d(b2c(substr(stuff,2,3))) +1
TotalPalette = (2**colorres)**3
sortflag = c2d(b2c(substr(stuff,5,1)))
sizeotable = c2d(b2c(substr(stuff,6,3)))+1
backgrd = c2d(substr(lsd,6,1))
ratio = c2d(substr(lsd,7,1))
if ratio=0 then ratio=1
header=header || lsd
if debug then
do
say "Screen Width : "width
say "Screen Height : "height
if GlobalColor then say "Global Color Map: Yes"
else say "Global Color Map: No"
say "Color Resolution : "ColorRes" bits ("TotalPalette" Total Palette)"
if Sortflag then say "Palette sorted by decreasing importance"
else say "Palette unsorted"
Say "Bitplanes : "sizeotable" ("2**sizeotable" colors)"
say "Background color : #"backgrd
say "Pixel Ratio : "ratio
end
/*
** read global color table (maybe)
** 3 bytes * 2^bitplates
*/
gct=""
if Globalcolor=1 then
do
if debug then say "Reading global color table"
GCT = readch('in',3*(2**sizeotable))
if debug then
do x = 1 to (2**sizeotable) by 2
say "Color "||right(X,2,'0')||" RGB "c2x(substr(gct,(x-1)*3+1,3))" Color "||right(x+1,2,'0')|| " RGB "c2x(substr(gct,(x-1)*3+2,3))
end
end
/*
** Getting ready to split files.
** First, figure out name to use for files. Double check
** to see if there's a ".GIF" extension.
**
** Since I use this mostly for web gifs, many web banner type
** gifs don't have a ".GIF" Extension, so I want to be safe.
*/
filecount=1
dt = lastpos('.',filename)
sl = lastpos('/',filename)
if dt=0 | dt<sl then
do
filestart=filename
fileend=".Gif"
end
else
do
filestart = left(filename,dt-1)
fileend = delstr(filename,1,dt-1)
end
do while ~eof('in')
nx = readch('in',1)
do while nx~="2C"x & Nx~='3B'x
if nx = '21'x then
do
if debug then say 'Gif Extension code'
bltype = readch('in',1)
len = c2d(readch('in',1))
if debug then
do
select
when bltype = 'F9'x then say "Graphic Control Extension"
When bltype = 'FE'x then say "Comment Extension"
When bltype = '01'x then say "Play Text Extension"
When bltype = 'FF'x then say "Application Extension"
otherwise say "Unknown Extension of hex type "c2x(bltype)
end
end
if bltype = 'FF'x then
do
call readch('in',len) /* Application Extension type */
BlkLen = c2d(readch('in',1)) /* read length of extension type */
call readch('in',blklen) /* read Application Extension data */
end
else
do
call readch('in',len) /* read in other extension data */
end
ending = readch('in',1)
if ending~='00'x then
do
say "No data terminator for this block, exiting..."
exit 10
end
end
else
do
say "Somethings wrong. Hex character "c2x(nx)" found. Exiting..."
exit 10
end
nx = readch('in',1)
end
if nx='3b'x then
do
say "File termination found, exiting..."
call close('in')
exit 0
end
say 'Found image number 'filecount
lct=""
code.=""
codecount = 0
codehead = nx||readch('in',9)
imageleft = c2d(reverse(substr(codehead,2,2)))
imagetop = c2d(reverse(substr(codehead,4,2)))
imagewidth = c2d(reverse(substr(codehead,6,2)))
imageheight = c2d(reverse(substr(codehead,8,2)))
stuff = c2b(right(codehead,1))
localcolor = left(stuff,1)
interlace = substr(stuff,2,1)
localsortflag = substr(stuff,3,1)
localcolortable = c2d(b2c(right(stuff,3)))+1
if debug then
do
say "Image Left : " imageleft
say "Image Top : " Imagetop
say "Image Width : " Imagewidth
say "Image Height: " Imageheight
if localcolor then say "Local Color Table : Yes"
else say "Local Color Table : No"
if interlace then say "Interlaced"
else say "Not Interlaced"
if localSortflag then say "Palette sorted by decreasing importance"
else say "Palette unsorted"
end
if localcolor=1 then
do
if debug then say "Reading local color table"
lCT = readch('in',3*(2**localcolortable))
if debug then
do x = 1 to (2**localcolortable) by 2
say "Color "||right(X,2,'0')||" RGB "c2x(substr(Lct,(x-1)*3+1,3))" Color "||right(x+1,2,'0')|| " RGB "c2x(substr(Lct,(x-1)*3+2,3))
end
end
bitsize = readch('in',1)
codecount = codecount+1
code.codecount = bitsize
codesize =readch('in',1)
code.codecount=code.codecount||codesize
chsz = c2d(codesize)
do while chsz>0
code.codecount = code.codecount|| readch('in',chsz)
codecount=codecount+1
codesize = readch('in',1)
chsz=c2d(codesize)
code.codecount = codesize
end
if debug then say "End of image."
/* write file */
call open('out',filestart||'.'right(filecount,3,'0')||fileend,'W')
call writech('out',header||GCT|| codehead ||lct)
do x=1 to codecount
call writech('out',code.x)
end
call close('out')
filecount=filecount + 1
end
say "?? Premature End of File???"
close('in')